// 导入数据库模块
const db = require('../DB/index');
const router = require('../router/approver');

// 获取当前用户的所有考勤信息
exports.info=(req,res)=>{
    const obj = req.body
    const sql = `SELECT * FROM attendance_user WHERE user_id = '${obj.id}'`
    db.query(sql,(err,result)=>{
        if(err) return res.cc(err)
        res.send({
            status:0,
            message:'获取数据成功',
            data:result
        })
    })
}

// 根据user_id获取用户信息
exports.userId=(req,res)=>{
    const obj = req.body
    const sql = `SELECT name FROM user WHERE id = ${obj.id}`
    db.query(sql,(err,result)=>{
        if(err) return res.cc(err)
        if(result.length === 0) return res.cc('错误输入')
        res.send({
            status:0,
            data:result
        })
    })
}

// 根据年月，搜索用户当月考勤数据
exports.searchDate=(req,res)=>{
    const obj = req.body
    const sql = `SELECT * FROM attendance_user WHERE year = ${obj.year} AND month = ${obj.month}`
    db.query(sql,(err,result)=>{
        if(err) return res.cc(err)
        res.send({
            status:0,
            data:result 
        })
    })
}

// 通过考勤数据id获取当月考勤数据详情
exports.searchDateInfo = (req,res)=>{
    const obj = req.body
    const sql = `SELECT * FROM attendance_info WHERE user_id = ${obj.id}`
    db.query(sql,(err,result)=>{
        if(err) return res.cc(err)
        if(result.length == 0) return res.cc('数据错误')
        res.send({
            status:0,
            data:result
        })
    })
}

